package com.cindata

class WorkflowInstance
{
    String name

    Account account
    RiskWarning riskWarning
    Collateral collateral
    AbnormalMortgageBatch abnormalMortgageBatch

    Workflow workflow

    WorkflowInstanceStage stage

    WorkflowInstanceStatus status

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User createBy
    User modifyBy

    static mapping = {
        autowire true
    }

    static constraints = {
        name maxSize: 64, unique: true, nullable: false
        account nullable: true, blank: true
        riskWarning nullable: true, blank: true
        collateral nullable: true, blank: true
        abnormalMortgageBatch nullable: true, blank: true

        stage nullable: true, blank: false
        status nullable: true, blank: false

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}